package com.gz.im.backend.component.manage;


import com.gz.im.backend.pojo.MessageRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;


/**
 * @author GuoZhong
 * @description redisson 管理器
 * @date 2023/3/28 13:28
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class RedissonManage {

	private final RedissonClient redissonClient;
	private  RBlockingDeque<Long> blockingDeque;

	/**
	 *  发布消息
	 */

	public void publish(String topicName, MessageRequest messageRequest){
		RTopic topic = createTopic(topicName);
		topic.publish(messageRequest);
	}
	/**
	 *  消息
	 */
	public RTopic createTopic(String topicName){
		RTopic rTopic = redissonClient.getTopic(topicName);
		return rTopic;
	}
	/**
	 *  加入坐席队列
	 */
	public void putAgentQueue(Long agentId){
		blockingDeque = redissonClient.getBlockingDeque("agent:queue");
		blockingDeque.push(agentId);

	}
	/**
	 *  获取坐席队列
	 */
	public RBlockingDeque<Long> listAgentQueue(){
		return blockingDeque;
	}

	public void rmAgent(Long agentId) {

		blockingDeque.remove(agentId);
	}
}
